<?php
if ( !defined( "IN_OP" ) )
{
    exit( "You can't access this file directly..." );
}
if ( ( $curruser['acl'] < 255 || $curruser['acl'] == 255 && $curruser['prev_id'] != 0 ) && !SubAccountRight( $curruser, 1 ) )
{
    diemsg( "你不是管理者！" );
}
$ui = new UI();
$tpl = new Template2();
$conf = new Config();
$rs = getdb( "select * from lotto where open>='".date( "Y-m-d" )."' order by open" );
if ( $rs->eof )
{
    $ui->showErrorPage( "<p class=error>目前没有可以下注期数！</p>" );
    exit();
}
$open = $rs->f['open'];
$round = $rs->f['round'];
$lotto_id = $rs->f['id'];
$opnumber = $rs->f['n1'];
$rs->close();
$stopbet = $conf->get( "waitbet" );
$startmode = "";
if ( date( "Y-m-d" ) < $open )
{
    $startmode = "disabled";
}
else if ( date( "Y-m-d" ) == $open )
{
    if ( $stopbet <= date( "Hi" ) && 0 < $opnumber )
    {
        $startmode = "disabled";
    }
    else if ( date( "Hi" ) <= $conf->get( "startbet" ) )
    {
        $startmode = "disabled";
    }
}
$dt = date( "Y-m-d" );
$t1 = strtotime( $open." ".$stopbet );
$tpl->Set( "timestap", $t1 - systime( ) );
$tpl->set( "phptime", systime( ) );
$tpl->set( "open", $open );
$tpl->set( "round", d3( $round ) );
$tpl->set( "dt", $dt );
$tpl->set( "lotto_id", $lotto_id );
$total_win = array();
$ary = array();
$ary[2] = array( "rate" => 0, "amount" => 0, "count" => 0, "lost" => 0 );
$ary[3] = array( "rate" => 0, "amount" => 0, "count" => 0, "lost" => 0 );
$ary[4] = array( "rate" => 0, "amount" => 0, "count" => 0, "lost" => 0 );
$ary[5] = array( "rate" => 0, "amount" => 0, "count" => 0, "lost" => 0 );
$total_win[2] = 0;
$total_win[3] = 0;
$total_win[4] = 0;
$total_win[5] = 0;
$sql = "select amount,upercent,back5,rate,numbers from bet where lotto_id=".$lotto_id." and bettype=27 and rame in (0,9)";
$rs = getdb( $sql );
while ( !$rs->eof )
{
    $percent = 1;
    $percent = $rs->f['upercent'];
    if ( 0 < $percent )
    {
        $percent /= 100;
    }
    $tmp = $percent * $rs->f['amount'];
    $num = intval( substr( $rs->f['numbers'], 0, 1 ) );
     $ary[$num]['amount']  += $tmp;
    ++$ary[$num]['count'];
    $ary[$num]['lost'] ++;
    $total_win[$num] ++;
    $rs->movenext();
}
$rs->close();
$sql = "select numbers,amount,percent255,back5,rate from bet2 where lotto_id=".$lotto_id." and bettype=27 and rame in (0,9)";
$rs = getdb( $sql );
while ( !$rs->eof )
{
    $percent = $rs->f['percent255'];
    if ( 0 < $percent )
    {
        $percent /= 100;
    }
    $tmp = $percent * $rs->f['amount'];
    $num = intval( substr( $rs->f['numbers'], 0, 1 ) );
    $ary[$num]['amount']  += $tmp;
    ++$ary[$num]['count'];
    $ary[$num]['lost'] ++;
    $total_win[$num] ++;
    $rs->movenext();
}
$rs->close();
$sql = "select numbers,amount,back,rate from bet8 where lotto_id=".$lotto_id." and bettype=27 and rame in (0,9)";
$rs = getdb( $sql );
while ( !$rs->eof )
{
    $backs = $rs->f['back'];
    $tmp = $rs->f['amount'];
    $num = intval( substr( $rs->f['numbers'], 0, 1 ) );
     $ary[$num]['amount']  -= $tmp;
    $ary[$num]['lost'] --;
    $total_win[$num] --;
    $rs->movenext();
}
$rs->close();
$idisk = 1;
$rs = getdb( "select * from rate27 where lotto_id={$lotto_id} and disk={$idisk} order by subid" );
if ( $rs->eof )
{
    $ui->showErrorPage( "<p class=error>系统目前维护中，请稍後！</p>" );
    exit();
}
while ( !$rs->eof )
{
    $subid = $rs->f['subid'];
    $html = "<table width='100' border='1'><tr>";
    $i = 1;
    while ( $i <= 12 )
    {
        $html .= "<td>".$g_chinayear[$i]."&nbsp;<font color='#FF0000'>".$rs->f["r".d2( $i )]."</font></td>";
        if ( $i % 3 == 0 )
        {
            $html .= "</tr><tr>";
        }
        ++$i;
    }
    $html .= "</tr></table>";
    $tpl->set( "r27_{$subid}", $html );
    $rs->next();
}
$i = 1;
while ( $i <= 12 )
{
    $tpl->set( "num".$i, implode( ", ", array_values( $g_chinayearnumpic[$i] ) ) );
    ++$i;
}
$b61 = isset( $_COOKIE['b61'] ) ? $_COOKIE['b61'] : "";
$tpl->set( "b61", $b61 );
$b62 = isset( $_COOKIE['b62'] ) ? $_COOKIE['b62'] : "";
$tpl->set( "b62", $b62 );
$b63 = "";
$tpl->set( "b63", $b63 );
$tpl->set( "startnowdisable", $startmode );
$tpl->set( "money2", $ary[2]['amount'] );
$tpl->set( "win2", show_numbercolor( $total_win[2] - $ary[2]['lost'] ) );
$tpl->set( "money3", $ary[3]['amount'] );
$tpl->set( "win3", show_numbercolor( $total_win[3] - $ary[3]['lost'] ) );
$tpl->set( "money4", $ary[4]['amount'] );
$tpl->set( "win4", show_numbercolor( $total_win[4] - $ary[4]['lost'] ) );
$tpl->set( "money5", $ary[5]['amount'] );
$tpl->set( "win5", show_numbercolor( $total_win[5] - $ary[5]['lost'] ) );
$prot_user = array();
$j = 0;
$i = 0;
while ( $i < 10 )
{
    $name = $conf->get( "port_systemuser_".$i );
    if ( $name != "" )
    {
        $prot_user[$j] = $name;
        ++$j;
    }
    ++$i;
}
$userrame1 = "&nbsp;<select name=account style='display:none'><option value='' selected> </option>";
$i = 0;
while ( $i < $j )
{
    $userrame1 .= "<option value='".$prot_user[$i]."'>".$prot_user[$i]."</option>";
    ++$i;
}
$userrame1 .= "</select>";
$tpl->set( "select_usr1", $userrame1 );
include_once( "class_6h/class.menu.php" );
$fieldArr = array( "round" => $round, "open" => $open, "lotto_id" => $lotto_id, "split_id" => 1 );
$onlineMenu = new menu_6h( 2, $fieldArr );
$selectid = getvar( "select" ) == "" ? 0 : getvar( "select" );
$menuList = $onlineMenu->getMenu( $selectid );
$tpl->set( "menuList", $menuList );
$tpl->set( "selectid", $selectid );
unset( $onlineMenu );
$tpl->load( "main", "unow8.htm" );
$tpl->set( "jslang", $g_conf['language'] );
$tpl->show( "main" );
$ui->footer();
?>